//
//  HomePageViewController.m
//  PhotoStudio
//
//  Created by 华谕 on 2017/10/20.
//  Copyright © 2017年 HUYU. All rights reserved.
//

#import "HomePageViewController.h"
#import "SDCycleScrollView.h"
#import "LiveSearchViewController.h"
#import "ProductHomeModel.h"
#import "BannerModel.h"
#import "ProdTypeModel.h"
#import "ProductModel.h"
#import "ImagelistModel.h"
#import "ProductTypeViewController.h"
#import "GoodsDetailsViewController.h"
#import "PaymentChannelsViewController.h"
#import "DeliveryRequireViewController.h"
#import "LiveGoodsDetailViewController.h"
#import "ImageModel.h"

static NSString *cellPath = @"HomeCell";
static NSString * CellIdentifier = @"HomecollectCell";
static NSString * CellIHerder = @"HomeHerderCell";
static NSString * CellIfooter = @"HomefooterCell";
@interface HomePageViewController ()<UITableViewDelegate,UITableViewDataSource,SDCycleScrollViewDelegate,UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic, strong)UITableView *tableview;
@property (nonatomic, strong)UICollectionView *collectionView;
@property (nonatomic, strong)SDCycleScrollView *cycleScrollView;
@property (nonatomic, strong)UIView *navView;
@property (nonatomic, strong)ProductHomeModel *model;

@end

@implementation HomePageViewController
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.translucent = NO;
    _navView.hidden = NO;
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    _navView.hidden = YES;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self creatUI];
    [self requestProductionHomePage];
}

- (void)creatUI
{
    self.view.backgroundColor = BacksColor;
    self.navigationController.navigationBar.translucent = NO;
    self.navView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, STA_NAV_HEIGHT)];
    _navView.backgroundColor = [UIColor whiteColor];
    [self.navigationController.view addSubview:_navView];
    UIView *grayView = [[UIView alloc] initWithFrame:CGRectMake(20, STA_NAV_HEIGHT-35, SCREEN_WIDTH-40, 30)];
    grayView.backgroundColor = LinesColor;
    grayView.layer.cornerRadius = 15;
    grayView.layer.masksToBounds = YES;
    [_navView addSubview:grayView];
    UIImageView *imgView = [ZCControl createImageViewWithFrame:CGRectMake(10, 5, 20, 20) ImageName:@"shouyess"];
    imgView.contentMode = UIViewContentModeScaleAspectFit;
    [grayView addSubview:imgView];
    UILabel *pladerLab = [ZCControl createLabelWithFrame:CGRectMake(40, 0, SCREEN_WIDTH-120, 30) Font:12.0 Text:@"输入您要搜索的内容" Color:BlaTiColor];
    pladerLab.textAlignment = NSTextAlignmentCenter;
    [grayView addSubview:pladerLab];
    UIButton *searchBtn = [ZCControl createButtonWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-40, 30) ImageName:nil Target:self Action:@selector(searchBtnAction) Title:nil Font:14.0];
    searchBtn.backgroundColor = [UIColor clearColor];
    [grayView addSubview:searchBtn];
    
    self.tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-STA_NAV_HEIGHT-SCREER_HeiX-TABBAR_HEIGHT) style:UITableViewStylePlain];
    _tableview.delegate = self;
    _tableview.dataSource = self;
    _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableview.backgroundColor = BacksColor;
    [self.view addSubview:_tableview];
    self.tableview.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewHeaderData)];
    self.tableview.estimatedRowHeight = 0;
    self.tableview.estimatedSectionHeaderHeight = 0;
    self.tableview.estimatedSectionFooterHeight = 0;
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 185*displaywidth)];
    self.cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 185*displaywidth) delegate:self placeholderImage:nil];
    _cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
    _cycleScrollView.delegate = self;
    //是否自动轮播
    _cycleScrollView.autoScroll = YES;//是否自动轮播 bannerImageViewContentMode
    //图片样式
    _cycleScrollView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill;
    _cycleScrollView.clipsToBounds = YES;
    _cycleScrollView.currentPageDotColor = ThemeColor;
    _cycleScrollView.pageDotColor = [UIColor whiteColor];
    _cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleClassic;
    [headerView addSubview:_cycleScrollView];
    self.tableview.tableHeaderView = headerView;
    UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc]init];
    layout.minimumInteritemSpacing = 0;
    layout.minimumLineSpacing = 0;
    _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 100) collectionViewLayout:layout];
    _collectionView.backgroundColor = BacksColor;
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    _collectionView.scrollEnabled = NO;
    [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:CellIdentifier];
    [_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:CellIHerder];
    [_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:CellIfooter];
}

- (void)loadNewHeaderData
{
    [self requestProductionHomePage];
}

//搜索
- (void)searchBtnAction
{
    LiveSearchViewController *vc = [[LiveSearchViewController alloc] init];
    vc.areaId = @"1";
    [self.navigationController pushViewController:vc animated:YES];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0)
    {
        return 3;
    }
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellPath];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (_model)
    {
        if (indexPath.section == 0)
        {
            if (indexPath.row == 0)
            {
                NSArray *typeAry = _model.productTypeList;
                NSInteger num = typeAry.count;
                if (typeAry.count > 5)
                {
                    num = 5;
                }
                CGFloat W = SCREEN_WIDTH/5;
                for (int i = 0; i < num; i++)
                {
                    ProdTypeModel *typeModel = typeAry[i];
                    UIImageView *imageview = [ZCControl createImageViewWithFrame:CGRectMake((W-40*displaywidth)/2+W*i, 15*displaywidth, 40*displaywidth, 40*displaywidth) ImageName:@""];
                    NSString *nameStr = typeModel.typeName;
                    if (typeAry.count > 5 && i == 4)
                    {
                        imageview.image = [UIImage imageNamed:@"quanb"];
                        nameStr = @"全部";
                    }
                    else
                    {
                        [imageview sd_setImageWithURL:[NSURL URLWithString:typeModel.imgUrl]];
                    }
                    imageview.contentMode = UIViewContentModeScaleAspectFit;
                    imageview.layer.cornerRadius = 20*displaywidth;
                    imageview.layer.masksToBounds = YES;
                    [cell.contentView addSubview:imageview];
                    UILabel *nameLab = [ZCControl createLabelWithFrame:CGRectMake(W*i, 55*displayheight, W, 40*displaywidth) Font:12.0 Text:nameStr Color:RGB(77, 77, 77)];
                    nameLab.textAlignment = NSTextAlignmentCenter;
                    [cell.contentView addSubview:nameLab];
                    UIButton *btn = [ZCControl createButtonWithFrame:CGRectMake(W*i, 0, W, 95*displayheight) ImageName:nil Target:self Action:@selector(closeProdTypeAction:) Title:nil Font:12.0];
                    btn.backgroundColor = [UIColor clearColor];
                    btn.tag = 100+i;
                    [cell.contentView addSubview:btn];
                    
                }
                
            }
            else if (indexPath.row == 1)
            {
                NSArray *teachAry = _model.productTypeTechnologyList;
                if (teachAry.count > 0)
                {
                    for (int i = 0; i < teachAry.count; i++)
                    {
                        ImageModel *imgmodel = teachAry[i];
                        UIImageView *imageview = [ZCControl createImageViewWithFrame:CGRectMake(SCREEN_WIDTH/10*(2*i+1)-20*displaywidth, 15*displaywidth, 40*displaywidth, 40*displaywidth) ImageName:@"dan"];
                        [imageview sd_setImageWithURL:[NSURL URLWithString:imgmodel.imgUrl] placeholderImage:[UIImage imageNamed:@"dan"]];
                        [cell.contentView addSubview:imageview];
                        UILabel *nameLab = [ZCControl createLabelWithFrame:CGRectMake(SCREEN_WIDTH/5*i, 55*displaywidth, SCREEN_WIDTH/5, 40*displaywidth) Font:12.0 Text:imgmodel.typeName Color:RGB(77, 77, 77)];
                        nameLab.textAlignment = NSTextAlignmentCenter;
                        nameLab.lineBreakMode = NSLineBreakByTruncatingTail;
                        [cell.contentView addSubview:nameLab];
                        UIButton *btn = [ZCControl createButtonWithFrame:CGRectMake(SCREEN_WIDTH/5*i, 0, SCREEN_WIDTH/5, 95*displaywidth) ImageName:nil Target:self Action:@selector(closeItemAction:) Title:nil Font:12.0];
                        btn.backgroundColor = [UIColor clearColor];
                        btn.tag = 200+i;
                        [cell.contentView addSubview:btn];
                        
                    }
                }
                UIImageView *leftimageview = [ZCControl createImageViewWithFrame:CGRectMake(0, 105*displaywidth, SCREEN_WIDTH/2-3*displaywidth, 120*displaywidth) ImageName:@"zhifutongdao"];
                if (![_model.paymentChannelImg isEqualToString:@""])
                {
                    [leftimageview sd_setImageWithURL:[NSURL URLWithString:_model.paymentChannelImg] placeholderImage:[UIImage imageNamed:@"zhifutongdao"]];
                }
                leftimageview.contentMode = UIViewContentModeScaleAspectFill;
                leftimageview.layer.masksToBounds = YES;
                [cell.contentView addSubview:leftimageview];
                UIImageView *rightview = [ZCControl createImageViewWithFrame:CGRectMake(SCREEN_WIDTH/2+3*displaywidth, 105*displaywidth, SCREEN_WIDTH/2-3*displaywidth, 120*displaywidth) ImageName:@"disongxuqiu"];
                if (![_model.deliveryDemandImg isEqualToString:@""])
                {
                    [rightview sd_setImageWithURL:[NSURL URLWithString:_model.deliveryDemandImg] placeholderImage:[UIImage imageNamed:@"disongxuqiu"]];
                }
                rightview.contentMode = UIViewContentModeScaleAspectFill;
                rightview.layer.masksToBounds = YES;
                [cell.contentView addSubview:rightview];
                UIButton *leftbtn = [ZCControl createButtonWithFrame:CGRectMake(0, 0, SCREEN_WIDTH/2-3*displaywidth, 120*displaywidth) ImageName:nil Target:self Action:@selector(leftAction) Title:nil Font:12.0];
                leftbtn.backgroundColor = [UIColor clearColor];
                [leftimageview addSubview:leftbtn];
                UIButton *rightbtn = [ZCControl createButtonWithFrame:CGRectMake(0, 0, SCREEN_WIDTH/2-3*displaywidth, 120*displaywidth) ImageName:nil Target:self Action:@selector(rightAction) Title:nil Font:12.0];
                rightbtn.backgroundColor = [UIColor clearColor];
                [rightview addSubview:rightbtn];
                
            }
            else if (indexPath.row == 2)
            {
                BannerModel *horModel = _model.horizontalAD;
                CGFloat H = 0;
                if (horModel)
                {
                    UIImageView *horimageview = [ZCControl createImageViewWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 120*displaywidth) ImageName:@""];
                    [horimageview sd_setImageWithURL:[NSURL URLWithString:horModel.imgUrl]];
                    horimageview.contentMode = UIViewContentModeScaleAspectFill;
                    horimageview.layer.masksToBounds = YES;
                    [cell.contentView addSubview:horimageview];
                    H += 120*displaywidth;
                }
                
                NSArray *squareAry = _model.squareADList;
                NSInteger squNum = squareAry.count;
                if (squareAry.count > 4)
                {
                    squNum = 4;
                }
                CGFloat squaW = SCREEN_WIDTH/2-2.5*displaywidth;
                for (int i = 0; i < squNum; i++)
                {
                    BannerModel *squaModel = squareAry[i];
                    UIImageView *imageview = [ZCControl createImageViewWithFrame:CGRectMake((SCREEN_WIDTH/2+2.5*displaywidth)*(i%2), H+125*displaywidth*(i/2), squaW, 120*displaywidth) ImageName:@""];
                    [imageview sd_setImageWithURL:[NSURL URLWithString:squaModel.imgUrl]];
                    imageview.contentMode = UIViewContentModeScaleAspectFill;
                    imageview.layer.masksToBounds = YES;
                    [cell.contentView addSubview:imageview];
                }
            }
        }
        else
        {
            NSArray *producAry = _model.productTypeList;
            cell.backgroundColor = BacksColor;
            if (producAry.count > 0)
            {
                CGFloat Height = 0;
                for (ProdTypeModel *typeModel in producAry)
                {
                    Height += 30*displaywidth;
                    NSArray *sizeAry = typeModel.productList;
                    if (sizeAry.count > 0)
                    {
                        Height += 245*displaywidth;
                    }
                    if (sizeAry.count > 2)
                    {
                        Height += 245*displaywidth;
                    }
                    if (![typeModel.horizontal isEqualToString:@""])
                    {
                        Height += 120*displaywidth;
                    }
                }
                [_collectionView removeFromSuperview];
                _collectionView.frame = CGRectMake(0, 0, SCREEN_WIDTH, Height);
                _model.cellHeight = Height;
                [cell.contentView addSubview:_collectionView];
//                [_collectionView reloadData];
            }
        }
    }
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)
    {
        if (indexPath.row == 0)
        {
            return 95*displaywidth;
        }
        else if (indexPath.row == 1)
        {
            return 235*displaywidth;
        }
        else
        {
            if (_model)
            {
                BannerModel *horModel = _model.horizontalAD;
                CGFloat H = 0;
                if (horModel)
                {
                    H += 120*displaywidth;
                }
                NSArray *squareAry = _model.squareADList;
                NSInteger squNum = squareAry.count;
                if (squNum > 0)
                {
                    H+=120*displaywidth;
                    if (squNum > 2)
                    {
                        H+=125*displaywidth;
                    }
                }
                return H;
            }
            return 365*displaywidth;
        }
    }
    else
    {
        if (_model.cellHeight > 0)
        {
            return _model.cellHeight;
        }
        NSArray *producAry = _model.productTypeList;
        if (producAry.count > 0)
        {
            CGFloat Height = 0;
            for (ProdTypeModel *typeModel in producAry)
            {
                Height += 30*displaywidth;
                NSArray *sizeAry = typeModel.productList;
                if (sizeAry.count > 0)
                {
                    Height += 245*displaywidth;
                }
                if (sizeAry.count > 2)
                {
                    Height += 245*displaywidth;
                }
                if (![typeModel.horizontal isEqualToString:@""])
                {
                    Height += 120*displaywidth;
                }
            }
            return Height;
        }
        return 0;
    }
    
}



-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    NSArray *producAry = _model.productTypeList;
    return producAry.count;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    NSArray *producAry = _model.productTypeList;
    ProdTypeModel *typeModel = producAry[section];
    NSArray *sizeAry = typeModel.productList;
    return sizeAry.count;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
    for (id subView in cell.contentView.subviews) {
        [subView removeFromSuperview];
    }
    CGFloat W = SCREEN_WIDTH/2;
    CGFloat X = 0;
    if (indexPath.row %2 == 1)
    {
        X = 7.5*displaywidth;
    }
    if (_model)
    {
        NSArray *producBigAry = _model.productTypeList;
        ProdTypeModel *typeModel = producBigAry[indexPath.section];
        NSArray *producAry = typeModel.productList;
        cell.backgroundColor = BacksColor;
        if (producAry.count > 0)
        {
            ProductModel *productModel = producAry[indexPath.row];
            UIView *whiteView = [[UIView alloc] initWithFrame:CGRectMake(X, 0, W-7.5*displaywidth, 240*displaywidth)];
            whiteView.backgroundColor = [UIColor whiteColor];
            [cell.contentView addSubview:whiteView];
            UIImageView *imageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, W-7.5*displaywidth, 170*displaywidth)];
            if (![productModel.logoImgUrl isEqualToString:@""])
            {
                [imageView1 sd_setImageWithURL:[NSURL URLWithString:productModel.logoImgUrl]];
            }
            imageView1.contentMode = UIViewContentModeScaleAspectFill;
            imageView1.layer.masksToBounds = YES;
            [whiteView addSubview:imageView1];
            UILabel *titlab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 170*displaywidth, W-37.5*displaywidth, 25*displaywidth) Font:12.0 Text:productModel.productName Color:RGB(77, 77, 77)];
            titlab.lineBreakMode = NSLineBreakByTruncatingTail;
            titlab.adjustsFontSizeToFitWidth = NO;
            [cell.contentView addSubview:titlab];
            UILabel *priceLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 200*displaywidth, W-37.5*displaywidth, 15*displaywidth) Font:12.0 Text:[NSString stringWithFormat:@"￥%.1lf元 +",[productModel.price floatValue]] Color:priceColor];
            [cell.contentView addSubview:priceLab];
            UILabel *integralLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 217.5*displaywidth, (W-37.5*displaywidth)/2, 15*displaywidth) Font:11.0 Text:[NSString stringWithFormat:@"%@积分",productModel.integral] Color:[UIColor whiteColor]];
            integralLab.textAlignment = NSTextAlignmentCenter;
            integralLab.layer.cornerRadius = 2;
            integralLab.layer.masksToBounds = YES;
            integralLab.backgroundColor = RGB(24, 159, 186);
            [cell.contentView addSubview:integralLab];
            CGRect bounds1 = [integralLab.text boundingRectWithSize:CGSizeMake(W-37.5*displaywidth, 15*displaywidth) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:NormalFontWithSize(11.0+fontScale)} context:nil];
            CGFloat width1 = bounds1.size.width+10;
            if (bounds1.size.width > (W-37.5*displaywidth)/2)
            {
                width1 = (W-37.5*displaywidth)/2;
            }
            integralLab.frame = CGRectMake(15*displaywidth, 217.5*displaywidth, width1, 15*displaywidth);
            UILabel *numLab = [ZCControl createLabelWithFrame:CGRectMake(100*displaywidth, 215*displaywidth, 80*displaywidth, 20*displaywidth) Font:12.0 Text:[NSString stringWithFormat:@" %@购买",productModel.productSales] Color:RGB(179, 179, 179)];
            [cell.contentView addSubview:numLab];
            
        }
    }
    
    
    return cell;
}

//定义每一个cell的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(SCREEN_WIDTH/2, 245*displaywidth);
}

//cell的点击事件
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSArray *producBigAry = _model.productTypeList;
    ProdTypeModel *typeModel = producBigAry[indexPath.section];
    NSArray *producAry = typeModel.productList;
    ProductModel *productModel = producAry[indexPath.row];
    LiveGoodsDetailViewController *vc = [[LiveGoodsDetailViewController alloc] init];
    vc.idStr = s_str(productModel.ID);
    vc.isProbject = YES;
    [self.navigationController pushViewController:vc animated:YES];
}


-(CGSize)collectionView:(UICollectionView*)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
{
    NSLog(@"---header---%ld--------",section);
    CGSize size = {SCREEN_WIDTH, 30*displaywidth};
    return size;
    
}

-(CGSize)collectionView:(UICollectionView*)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section
{
    NSLog(@"---footer----%ld--------",section);
    NSArray *producBigAry = _model.productTypeList;
    ProdTypeModel *prodtypeModel = producBigAry[section];
    if ([prodtypeModel.horizontal isEqualToString:@""])
    {
        CGSize size = {SCREEN_WIDTH, 0};
        return size;
    }
    CGSize size = {SCREEN_WIDTH, 120*displaywidth};
    return size;
    
}

//在表头内添加内容,需要创建一个继承collectionReusableView的类,用法类比tableViewcell
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"----%ld--------",indexPath.section);
    UICollectionReusableView *headerView = nil;
    if (kind == UICollectionElementKindSectionHeader)
    {
        headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:CellIHerder forIndexPath:indexPath];
        headerView.backgroundColor = [UIColor whiteColor];
        for (id subView in headerView.subviews) {
            [subView removeFromSuperview];
        }
        NSArray *producBigAry = _model.productTypeList;
        ProdTypeModel *prodtypeModel = producBigAry[indexPath.section];
        UILabel *nameLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 0, SCREEN_WIDTH-30*displaywidth, 30*displaywidth) Font:13.0 Text:prodtypeModel.typeName Color:BlaTiColor];
        [headerView addSubview:nameLab];
        UIView *lineV = [[UIView alloc] initWithFrame:CGRectMake(0, 29*displaywidth, SCREEN_WIDTH, 1*displaywidth)];
        lineV.backgroundColor = BacksColor;
        [headerView addSubview:lineV];
    }
    if (kind == UICollectionElementKindSectionFooter)
    {
        headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:CellIfooter forIndexPath:indexPath];
        headerView.backgroundColor = [UIColor whiteColor];
        for (id subView in headerView.subviews) {
            [subView removeFromSuperview];
        }
        NSArray *producBigAry = _model.productTypeList;
        ProdTypeModel *prodtypeModel = producBigAry[indexPath.section];
        UIImageView *horimageview = [ZCControl createImageViewWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 120*displaywidth) ImageName:@""];
        [horimageview sd_setImageWithURL:[NSURL URLWithString:prodtypeModel.horizontal]];
        horimageview.contentMode = UIViewContentModeScaleAspectFill;
        horimageview.layer.masksToBounds = YES;
        [headerView addSubview:horimageview];
    }
    return headerView;
}

//支付通道
- (void)leftAction
{
    PaymentChannelsViewController *vc = [[PaymentChannelsViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

//递送需求
- (void)rightAction
{
    DeliveryRequireViewController *vc = [[DeliveryRequireViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}


//技术分类
- (void)closeItemAction:(UIButton *)btn
{
    NSInteger index = btn.tag-200;
    NSArray *teachAry = _model.productTypeTechnologyList;
    ImageModel *model = teachAry[index];
    GoodsDetailsViewController *vc = [[GoodsDetailsViewController alloc] init];
    vc.idStr = model.ID;
    [self.navigationController pushViewController:vc animated:YES];
}


- (void)closeProdTypeAction:(UIButton *)btn
{
    NSArray *typeAry = _model.productTypeList;
    ProdTypeModel *model = typeAry[btn.tag-100];
    ProductTypeViewController *vc = [[ProductTypeViewController alloc] init];
    vc.areaid = @"1";
    if (typeAry.count > 5 && btn.tag == 104)
    {
        vc.isAll = YES;
        vc.titStr = @"分类列表";
    }
    else
    {
        vc.parentId = model.ID;
        vc.titStr = model.typeName;
        vc.isAll = NO;
    }
    [self.navigationController pushViewController:vc animated:YES];

}

- (void)requestProductionHomePage
{
    WEAKSELF;
    [HYBaseHandler requestWithTheFormUrl:SERVER_NewProductHom Parmers:nil Success:^(id obj) {
        [weakSelf.tableview.mj_header endRefreshing];
        if ([obj server_Getcodecheck])
        {
            weakSelf.model = [ProductHomeModel mj_objectWithKeyValues:obj[@"data"]];
            dispatch_async(dispatch_get_main_queue(), ^{
                NSArray *bannerAry = weakSelf.model.bannerList;
                NSMutableArray *imgAry = [NSMutableArray arrayWithCapacity:0];
                for (BannerModel *model in bannerAry)
                {
                    [imgAry addObject:model.imgUrl];
                }
                weakSelf.cycleScrollView.imageURLStringsGroup = imgAry;
                [weakSelf.tableview reloadData];
                [weakSelf.collectionView reloadData];
            });
        }
        else
        {
            [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
        }
    } failed:^(NSError *error) {
        [weakSelf.tableview.mj_header endRefreshing];

    }];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
